import React, {useContext} from "react";
import {context} from './AuthProvider'
import {Navigate} from "react-router-dom";
import {loginByToken} from "../store/actions";
import {ThunkDispatch} from "redux-thunk";
import {AnyAction} from "redux";
import {useDispatch} from "react-redux";

const AuthorizedRouter = ({children}: any) => {
    const {token} = useContext<any>(context);
    type State = { a: object }; // your state type
    type AppDispatch = ThunkDispatch<State, any, AnyAction>;
    const dispatch: AppDispatch = useDispatch();
    console.log(token);
    // dispatch(loginByToken(token) as any).then((response: any) => {



    // });

    debugger;
    if (token !== '') {
        return children;
    } else {
        return <Navigate to="/login" replace={true}/>
    }

};

export default AuthorizedRouter;
